package cn.edu.zut.service;

import cn.edu.zut.dao.BorrowBookDao;
import cn.edu.zut.model.Book;
import cn.edu.zut.model.BorrowBook;
import cn.edu.zut.model.Reader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BorrowBookServiceImpl implements BorrowBookService {
    @Autowired
    BorrowBookDao borrowBookDao;

    BorrowBook borrowBook;




    public int insertBorrowerInfo(BorrowBook borrowBook) {
        int row=borrowBookDao.insertBorrowerInfo(borrowBook);
        return row;
    }
    public int deleteBorrowInfo(BorrowBook borrowBook) {
        int row=borrowBookDao.deleteBorrowInfo(borrowBook);
        return row;
    }
    public int updateBorrowInfo(BorrowBook borrowBook) {        //更新还书信息
        int row=borrowBookDao.updateBorrowInfo(borrowBook);
        return row;
    }
    public int updateBorrowByBookId(BorrowBook borrowBook) {
        int row=borrowBookDao.updateBorrowByBookId(borrowBook);
        return row;
    }

    public int updateBorrowFlag(BorrowBook borrowBook) {
        int row=borrowBookDao.updateBorrowFlag(borrowBook);    //更新借书状态
        return row;
    }
    public List<BorrowBook> selectBorrowBookInfo(String readerId){
        List<BorrowBook> borrowBooks=borrowBookDao.selectBorrowBookInfo(readerId);
//        for (BorrowBook borrowBook:borrowBooks
//        ) {
//            System.out.println(borrowBook.toString());
//        }
        return borrowBooks;
    }
    public List<Book> selectBooksByReaderId(String readerId){
        List<Book> books=borrowBookDao.selectBooksByReaderId(readerId);
        for (Book book:books
        ) {
            System.out.println(book.toString());
        }
        return books;
    }
    public Reader selectReaderByReaderId(String readerId){
        Reader reader = borrowBookDao.selectReaderByReaderId(readerId);
        return reader;
    }
}
